﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SportsStore.Domain.Abstract;

namespace SportsStore.WebUI.Controllers
{
    public class NavController : Controller
    {
        private IProductsRepository repository;

        public NavController(IProductsRepository repo)
        {
            repository = repo;
        }


        //public PartialViewResult menu(string category=null,bool horizontalLayout=false) 第10章弃用更新为下面方法
        public PartialViewResult menu(string category=null)
        {
            ViewBag.SelectCategory = category;//选中表现

            IEnumerable<string> categories = repository.Products
            .Select(x => x.Category)
            .Distinct()
            .OrderBy(x => x);

            //string viewName = horizontalLayout ? "MenuHorizontal" : "Menu";
            //return PartialView(viewName,categories);  第10章弃用更新为下面方法
            return PartialView("FlexMenu",categories);
        }

        //// GET: Nav 初始状态响应
        //public string Menu()
        //{
        //    return "Hello from NavController";
        //}
    }
}